package cliente.gui;

import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import cliente.gui.GUIModCategoria;

import comun.dto.*;



public class GUIABMCategoria extends JFrame {

    /** Creates new form GUIModificarCategoria */
    public GUIABMCategoria() {
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    	 jPanel1 = new javax.swing.JPanel();
         jScrollPane1 = new javax.swing.JScrollPane();
         tablaCategorias = new javax.swing.JTable();
         buscar = new javax.swing.JButton();
         alta = new javax.swing.JButton();
         salir = new javax.swing.JButton();
         eliminar = new javax.swing.JButton();
         modificar = new javax.swing.JButton();
         jLabel1 = new javax.swing.JLabel();
         jLabel2 = new javax.swing.JLabel();
         jLabel3 = new javax.swing.JLabel();
         nombre = new javax.swing.JTextField();
         salario = new javax.swing.JTextField();
         fecha = new com.toedter.calendar.JDateChooser();

         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
         setTitle("Alta, Baja y Modificacion de Categoria de Empleado");
   
         
         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("ABM de Categoria de Empleado"));

         tablaCategorias.setModel(new javax.swing.table.DefaultTableModel(
             new Object [][] {

             },
             new String [] {
                 "Nombre", "fecha", "Salario"
             }
         ) {
             Class[] types = new Class [] {
                 java.lang.String.class, java.lang.String.class, java.lang.String.class
             };

             public Class getColumnClass(int columnIndex) {
                 return types [columnIndex];
             }
         });
         jScrollPane1.setViewportView(tablaCategorias);

         buscar.setText("Listar Categorias");

         alta.setText("Alta");

         salir.setText("Salir");

         eliminar.setText("Eliminar");

         modificar.setText("Modificar");

         jLabel1.setText("Nombre :");

         jLabel2.setText("Fecha: ");

         jLabel3.setText("salario: ");

         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
         jPanel1.setLayout(jPanel1Layout);
         jPanel1Layout.setHorizontalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addGap(6, 6, 6)
                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 492, javax.swing.GroupLayout.PREFERRED_SIZE))
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel1)
                     .addComponent(jLabel2)
                     .addComponent(jLabel3))
                 .addGap(12, 12, 12)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                     .addComponent(fecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addComponent(salario, javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(nombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))
                 .addGap(173, 173, 173))
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addComponent(buscar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addGap(518, 518, 518))
             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                 .addGap(53, 53, 53)
                 .addComponent(alta, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                 .addComponent(modificar, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(eliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                 .addComponent(salir, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addGap(183, 183, 183))
         );
         jPanel1Layout.setVerticalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addComponent(buscar)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel1)
                     .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addComponent(jLabel2)
                     .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel3)
                     .addComponent(salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(alta)
                     .addComponent(modificar)
                     .addComponent(eliminar)
                     .addComponent(salir)))
         );

         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addContainerGap())
         );

         pack();
    }// </editor-fold>


    // Variables declaration - do not modify
    private javax.swing.JButton alta;
    private javax.swing.JButton buscar;
    private javax.swing.JButton eliminar;
    private com.toedter.calendar.JDateChooser fecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton modificar;
    private javax.swing.JTextField nombre;
    private javax.swing.JTextField salario;
    private javax.swing.JButton salir;
    private javax.swing.JTable tablaCategorias;
    // End of variables declaration

    
    

    
    
    
    
    public JTextField getNombre(){
    	return nombre;
    }
    
    public JTextField getSalario(){
    	return salario;
    }
    
    public void setNombre( JTextField nombre){
    	this.nombre=nombre;
    }
    
    public void setSalario( JTextField salario){
    	this.salario=salario;
    }
    /**
     * @return the alta
     */
    public javax.swing.JButton getAlta() {
        return alta;
    }

    /**
     * @param alta the alta to set
     */
    public void setAlta(javax.swing.JButton alta) {
        this.alta = alta;
    }

    /**
     * @return the buscar
     */
    public javax.swing.JButton getBuscar() {
        return buscar;
    }

    /**
     * @param buscar the buscar to set
     */
    public void setBuscar(javax.swing.JButton buscar) {
        this.buscar = buscar;
    }

    /**
     * @return the eliminar
     */
    public javax.swing.JButton getEliminar() {
        return eliminar;
    }

    /**
     * @param eliminar the eliminar to set
     */
    public void setEliminar(javax.swing.JButton eliminar) {
        this.eliminar = eliminar;
    }

    /**
     * @return the modificar
     */
    public javax.swing.JButton getModificar() {
        return modificar;
    }

    /**
     * @param modificar the modificar to set
     */
    public void setModificar(javax.swing.JButton modificar) {
        this.modificar = modificar;
    }

    /**
     * @return the salir
     */
    public javax.swing.JButton getSalir() {
        return salir;
    }

    /**
     * @param salir the salir to set
     */
    public void setSalir(javax.swing.JButton salir) {
        this.salir = salir;
    }

    /**
     * @return the tablaCategorias
     */
    public javax.swing.JTable getTablaCategorias() {
        return tablaCategorias;
    }

    /**
     * @param tablaCategorias the tablaCategorias to set
     */
    public void setTablaCategorias(javax.swing.JTable tablaCategorias) {
        this.tablaCategorias = tablaCategorias;
    }

    public String getNombCat(int fila){
    	return tablaCategorias.getValueAt(fila, 0).toString();
    	
    }
    
    public String getFechaCat(int fila){
    	return tablaCategorias.getValueAt(fila, 1).toString();
    	
    }
    
    public String getSalarioCat(int fila){
    	return tablaCategorias.getValueAt(fila, 2).toString();
    	
    }
    
    
	public void setTablCategoria(){
		tablaCategorias.setModel(new javax.swing.table.DefaultTableModel(
				new Object [][] {
					
				},
				new String [] {
						"Nombre","Fecha", "Salario"
				}
				));
	}
	
	public void setTablaCategorias(java.util.Vector  categorias){
		CategoriaDTO cat;
		int i=0;
		Object datos[]=new Object[4];
		while (!categorias.isEmpty()){
			DefaultTableModel m=(DefaultTableModel)tablaCategorias.getModel();
			String[] filavacia=new String[2];
			m.addRow(filavacia);
			cat=(CategoriaDTO) categorias.get(0);
			tablaCategorias.setValueAt(cat.getNombre(), i, 0);
			tablaCategorias.setValueAt(cat.getFecha(), i, 1);
			tablaCategorias.setValueAt(cat.getSalario(), i, 2);
			
			categorias.remove(0);
			i++;
			
		}
	}
	
 	public void insertarFila(){
		String[] filavacia=new String[4];
		DefaultTableModel m=(DefaultTableModel)tablaCategorias.getModel();
		m.addRow(filavacia);
		tablaCategorias.setModel(m);

	}
	
	public void setTablaCategoria(int fila){
		int i=tablaCategorias.getRowCount()-1;
		while (fila<i){			
			tablaCategorias.setValueAt(tablaCategorias.getValueAt(fila+1,0), fila, 0);
			tablaCategorias.setValueAt(tablaCategorias.getValueAt(fila+1,1), fila, 1);
			tablaCategorias.setValueAt(tablaCategorias.getValueAt(fila+1,2), fila, 2);	
			fila++;			
		}
		DefaultTableModel m=(DefaultTableModel)tablaCategorias.getModel();
		m.removeRow(i);
	}
	
	
	   public Date getDate() {
	        return fecha.getDate();
	    } 
	   
	   public com.toedter.calendar.JDateChooser getFecha(){
		   return fecha;
	   }
	
    public void setActionListeners(ActionListener lis) {
        buscar.addActionListener(lis);
        alta.addActionListener(lis);
        modificar.addActionListener(lis);
        eliminar.addActionListener(lis);
        salir.addActionListener(lis);
        
    }


}
